
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 11/28/2013 01:00:32
-- Generated from EDMX file: C:\Users\Daniel\Desktop\sistema-academicoTCC\SistemaAcademicoTCCDAO\Model.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [SATCC];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[FK_AlunoTurma]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AlunoSet] DROP CONSTRAINT [FK_AlunoTurma];
GO
IF OBJECT_ID(N'[dbo].[FK_AlunoUser]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AlunoSet] DROP CONSTRAINT [FK_AlunoUser];
GO
IF OBJECT_ID(N'[dbo].[FK_AulaTurma]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AulaSet] DROP CONSTRAINT [FK_AulaTurma];
GO
IF OBJECT_ID(N'[dbo].[FK_CursoProfessor]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[CursoSet] DROP CONSTRAINT [FK_CursoProfessor];
GO
IF OBJECT_ID(N'[dbo].[FK_TurmaCurso]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[TurmaSet] DROP CONSTRAINT [FK_TurmaCurso];
GO
IF OBJECT_ID(N'[dbo].[FK_UserProfessor]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[ProfessorSet] DROP CONSTRAINT [FK_UserProfessor];
GO
IF OBJECT_ID(N'[dbo].[FK_AulaMateria_AulaSet]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AulaMateria] DROP CONSTRAINT [FK_AulaMateria_AulaSet];
GO
IF OBJECT_ID(N'[dbo].[FK_AulaMateria_MateriaSet]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AulaMateria] DROP CONSTRAINT [FK_AulaMateria_MateriaSet];
GO
IF OBJECT_ID(N'[dbo].[FK_AulaProfessor_AulaSet]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AulaProfessor] DROP CONSTRAINT [FK_AulaProfessor_AulaSet];
GO
IF OBJECT_ID(N'[dbo].[FK_AulaProfessor_ProfessorSet]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AulaProfessor] DROP CONSTRAINT [FK_AulaProfessor_ProfessorSet];
GO
IF OBJECT_ID(N'[dbo].[FK_AulaUnitariaAula_AulaSet]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AulaUnitariaAula] DROP CONSTRAINT [FK_AulaUnitariaAula_AulaSet];
GO
IF OBJECT_ID(N'[dbo].[FK_AulaUnitariaAula_AulaUnitariaSet]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AulaUnitariaAula] DROP CONSTRAINT [FK_AulaUnitariaAula_AulaUnitariaSet];
GO
IF OBJECT_ID(N'[dbo].[FK_Habilitado_MateriaSet]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Habilitado] DROP CONSTRAINT [FK_Habilitado_MateriaSet];
GO
IF OBJECT_ID(N'[dbo].[FK_Habilitado_ProfessorSet]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[Habilitado] DROP CONSTRAINT [FK_Habilitado_ProfessorSet];
GO
IF OBJECT_ID(N'[dbo].[FK_MateriaCurso_CursoSet]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MateriaCurso] DROP CONSTRAINT [FK_MateriaCurso_CursoSet];
GO
IF OBJECT_ID(N'[dbo].[FK_MateriaCurso_MateriaSet]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[MateriaCurso] DROP CONSTRAINT [FK_MateriaCurso_MateriaSet];
GO
IF OBJECT_ID(N'[dbo].[FK_PresencaAluno_AlunoSet]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PresencaAluno] DROP CONSTRAINT [FK_PresencaAluno_AlunoSet];
GO
IF OBJECT_ID(N'[dbo].[FK_PresencaAluno_PresencaSet]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PresencaAluno] DROP CONSTRAINT [FK_PresencaAluno_PresencaSet];
GO
IF OBJECT_ID(N'[dbo].[FK_PresencaAulaUnitaria_AulaUnitariaSet]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PresencaAulaUnitaria] DROP CONSTRAINT [FK_PresencaAulaUnitaria_AulaUnitariaSet];
GO
IF OBJECT_ID(N'[dbo].[FK_PresencaAulaUnitaria_PresencaSet]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[PresencaAulaUnitaria] DROP CONSTRAINT [FK_PresencaAulaUnitaria_PresencaSet];
GO
IF OBJECT_ID(N'[dbo].[FK_EnderecoSetUserSet]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[EnderecoSet] DROP CONSTRAINT [FK_EnderecoSetUserSet];
GO
IF OBJECT_ID(N'[dbo].[FK_AlunoSetAulaSet_AlunoSet]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AlunoSetAulaSet] DROP CONSTRAINT [FK_AlunoSetAulaSet_AlunoSet];
GO
IF OBJECT_ID(N'[dbo].[FK_AlunoSetAulaSet_AulaSet]', 'F') IS NOT NULL
    ALTER TABLE [dbo].[AlunoSetAulaSet] DROP CONSTRAINT [FK_AlunoSetAulaSet_AulaSet];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[dbo].[AlunoSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AlunoSet];
GO
IF OBJECT_ID(N'[dbo].[AulaSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AulaSet];
GO
IF OBJECT_ID(N'[dbo].[AulaUnitariaSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AulaUnitariaSet];
GO
IF OBJECT_ID(N'[dbo].[CursoSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[CursoSet];
GO
IF OBJECT_ID(N'[dbo].[MateriaSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MateriaSet];
GO
IF OBJECT_ID(N'[dbo].[PresencaSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PresencaSet];
GO
IF OBJECT_ID(N'[dbo].[ProfessorSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[ProfessorSet];
GO
IF OBJECT_ID(N'[dbo].[TurmaSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[TurmaSet];
GO
IF OBJECT_ID(N'[dbo].[UserSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[UserSet];
GO
IF OBJECT_ID(N'[dbo].[EnderecoSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[EnderecoSet];
GO
IF OBJECT_ID(N'[dbo].[AlunoSetAulaSet]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AlunoSetAulaSet];
GO
IF OBJECT_ID(N'[dbo].[AulaMateria]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AulaMateria];
GO
IF OBJECT_ID(N'[dbo].[AulaProfessor]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AulaProfessor];
GO
IF OBJECT_ID(N'[dbo].[AulaUnitariaAula]', 'U') IS NOT NULL
    DROP TABLE [dbo].[AulaUnitariaAula];
GO
IF OBJECT_ID(N'[dbo].[Habilitado]', 'U') IS NOT NULL
    DROP TABLE [dbo].[Habilitado];
GO
IF OBJECT_ID(N'[dbo].[MateriaCurso]', 'U') IS NOT NULL
    DROP TABLE [dbo].[MateriaCurso];
GO
IF OBJECT_ID(N'[dbo].[PresencaAluno]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PresencaAluno];
GO
IF OBJECT_ID(N'[dbo].[PresencaAulaUnitaria]', 'U') IS NOT NULL
    DROP TABLE [dbo].[PresencaAulaUnitaria];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'AlunoSet'
CREATE TABLE [dbo].[AlunoSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [nmAluno] nvarchar(max)  NOT NULL,
    [cdMatricula] nvarchar(max)  NOT NULL,
    [dtNasc] nvarchar(max)  NOT NULL,
    [cdCPF] nvarchar(max)  NOT NULL,
    [cdRG] nvarchar(max)  NOT NULL,
    [dsTelefone] nvarchar(max)  NOT NULL,
    [dsTelefone2] nvarchar(max)  NOT NULL,
    [dsEmail] nvarchar(max)  NOT NULL,
    [TurmaId] int  NOT NULL,
    [User_Id] int  NOT NULL
);
GO

-- Creating table 'AulaSet'
CREATE TABLE [dbo].[AulaSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Turma_Id] int  NOT NULL,
    [Professor_id] int  NOT NULL
);
GO

-- Creating table 'AulaUnitariaSet'
CREATE TABLE [dbo].[AulaUnitariaSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [dtAulaUnitaria] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'CursoSet'
CREATE TABLE [dbo].[CursoSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [nmCurso] nvarchar(max)  NOT NULL,
    [dsDescricao] nvarchar(max)  NOT NULL,
    [Professor_Id] int  NOT NULL
);
GO

-- Creating table 'MateriaSet'
CREATE TABLE [dbo].[MateriaSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [nmMateria] nvarchar(max)  NOT NULL,
    [dsCargaHorariaSemestral] int  NOT NULL
);
GO

-- Creating table 'PresencaSet'
CREATE TABLE [dbo].[PresencaSet] (
    [Id] int IDENTITY(1,1) NOT NULL
);
GO

-- Creating table 'ProfessorSet'
CREATE TABLE [dbo].[ProfessorSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [nmProfessor] nvarchar(max)  NOT NULL,
    [dtNasc] datetime  NOT NULL,
    [dsCPF] nvarchar(max)  NOT NULL,
    [dsRG] nvarchar(max)  NOT NULL,
    [dsTelefone] nvarchar(max)  NOT NULL,
    [dsTelefone2] nvarchar(max)  NOT NULL,
    [dsEmail] nvarchar(max)  NOT NULL,
    [dsFormacao] nvarchar(max)  NOT NULL,
    [User_Id] int  NOT NULL
);
GO

-- Creating table 'TurmaSet'
CREATE TABLE [dbo].[TurmaSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [cdPeriodo] nvarchar(max)  NOT NULL,
    [dtInicio] nvarchar(max)  NOT NULL,
    [Curso_Id] int  NOT NULL,
    [Atribuido] bit  NOT NULL
);
GO

-- Creating table 'UserSet'
CREATE TABLE [dbo].[UserSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [dsLogin] nvarchar(max)  NOT NULL,
    [dsSenha] nvarchar(max)  NOT NULL,
    [cdPermissao] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'EnderecoSet'
CREATE TABLE [dbo].[EnderecoSet] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [dsLogradouro] nvarchar(max)  NOT NULL,
    [dsEstado] nvarchar(max)  NOT NULL,
    [dsCEP] nvarchar(max)  NOT NULL,
    [dsBairro] nvarchar(max)  NOT NULL,
    [dsCidade] nvarchar(max)  NOT NULL,
    [AlunoSetId] int  NOT NULL,
    [UserSet_Id] int  NOT NULL
);
GO

-- Creating table 'AlunoSetAulaSet'
CREATE TABLE [dbo].[AlunoSetAulaSet] (
    [AlunoSet_Id] int  NOT NULL,
    [AulaSet_Id] int  NOT NULL,
    [Nota] float  NOT NULL,
    [Tipo] varchar(2)  NOT NULL
);
GO

-- Creating table 'AulaMateria'
CREATE TABLE [dbo].[AulaMateria] (
    [AulaSet_Id] int  NOT NULL,
    [MateriaSet_Id] int  NOT NULL
);
GO

-- Creating table 'AulaProfessor'
CREATE TABLE [dbo].[AulaProfessor] (
    [AulaSet_Id] int  NOT NULL,
    [ProfessorSet_Id] int  NOT NULL
);
GO

-- Creating table 'AulaUnitariaAula'
CREATE TABLE [dbo].[AulaUnitariaAula] (
    [AulaSet_Id] int  NOT NULL,
    [AulaUnitariaSet_Id] int  NOT NULL
);
GO

-- Creating table 'Habilitado'
CREATE TABLE [dbo].[Habilitado] (
    [MateriaSet_Id] int  NOT NULL,
    [ProfessorSet_Id] int  NOT NULL
);
GO

-- Creating table 'MateriaCurso'
CREATE TABLE [dbo].[MateriaCurso] (
    [CursoSet_Id] int  NOT NULL,
    [MateriaSet_Id] int  NOT NULL
);
GO

-- Creating table 'PresencaAluno'
CREATE TABLE [dbo].[PresencaAluno] (
    [AlunoSet_Id] int  NOT NULL,
    [PresencaSet_Id] int  NOT NULL
);
GO

-- Creating table 'PresencaAulaUnitaria'
CREATE TABLE [dbo].[PresencaAulaUnitaria] (
    [AulaUnitariaSet_Id] int  NOT NULL,
    [PresencaSet_Id] int  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'AlunoSet'
ALTER TABLE [dbo].[AlunoSet]
ADD CONSTRAINT [PK_AlunoSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'AulaSet'
ALTER TABLE [dbo].[AulaSet]
ADD CONSTRAINT [PK_AulaSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'AulaUnitariaSet'
ALTER TABLE [dbo].[AulaUnitariaSet]
ADD CONSTRAINT [PK_AulaUnitariaSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'CursoSet'
ALTER TABLE [dbo].[CursoSet]
ADD CONSTRAINT [PK_CursoSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'MateriaSet'
ALTER TABLE [dbo].[MateriaSet]
ADD CONSTRAINT [PK_MateriaSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'PresencaSet'
ALTER TABLE [dbo].[PresencaSet]
ADD CONSTRAINT [PK_PresencaSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ProfessorSet'
ALTER TABLE [dbo].[ProfessorSet]
ADD CONSTRAINT [PK_ProfessorSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'TurmaSet'
ALTER TABLE [dbo].[TurmaSet]
ADD CONSTRAINT [PK_TurmaSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'UserSet'
ALTER TABLE [dbo].[UserSet]
ADD CONSTRAINT [PK_UserSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'EnderecoSet'
ALTER TABLE [dbo].[EnderecoSet]
ADD CONSTRAINT [PK_EnderecoSet]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [AlunoSet_Id], [AulaSet_Id] in table 'AlunoSetAulaSet'
ALTER TABLE [dbo].[AlunoSetAulaSet]
ADD CONSTRAINT [PK_AlunoSetAulaSet]
    PRIMARY KEY CLUSTERED ([AlunoSet_Id], [AulaSet_Id] ASC);
GO

-- Creating primary key on [AulaSet_Id], [MateriaSet_Id] in table 'AulaMateria'
ALTER TABLE [dbo].[AulaMateria]
ADD CONSTRAINT [PK_AulaMateria]
    PRIMARY KEY NONCLUSTERED ([AulaSet_Id], [MateriaSet_Id] ASC);
GO

-- Creating primary key on [AulaSet_Id], [ProfessorSet_Id] in table 'AulaProfessor'
ALTER TABLE [dbo].[AulaProfessor]
ADD CONSTRAINT [PK_AulaProfessor]
    PRIMARY KEY NONCLUSTERED ([AulaSet_Id], [ProfessorSet_Id] ASC);
GO

-- Creating primary key on [AulaSet_Id], [AulaUnitariaSet_Id] in table 'AulaUnitariaAula'
ALTER TABLE [dbo].[AulaUnitariaAula]
ADD CONSTRAINT [PK_AulaUnitariaAula]
    PRIMARY KEY NONCLUSTERED ([AulaSet_Id], [AulaUnitariaSet_Id] ASC);
GO

-- Creating primary key on [MateriaSet_Id], [ProfessorSet_Id] in table 'Habilitado'
ALTER TABLE [dbo].[Habilitado]
ADD CONSTRAINT [PK_Habilitado]
    PRIMARY KEY NONCLUSTERED ([MateriaSet_Id], [ProfessorSet_Id] ASC);
GO

-- Creating primary key on [CursoSet_Id], [MateriaSet_Id] in table 'MateriaCurso'
ALTER TABLE [dbo].[MateriaCurso]
ADD CONSTRAINT [PK_MateriaCurso]
    PRIMARY KEY NONCLUSTERED ([CursoSet_Id], [MateriaSet_Id] ASC);
GO

-- Creating primary key on [AlunoSet_Id], [PresencaSet_Id] in table 'PresencaAluno'
ALTER TABLE [dbo].[PresencaAluno]
ADD CONSTRAINT [PK_PresencaAluno]
    PRIMARY KEY NONCLUSTERED ([AlunoSet_Id], [PresencaSet_Id] ASC);
GO

-- Creating primary key on [AulaUnitariaSet_Id], [PresencaSet_Id] in table 'PresencaAulaUnitaria'
ALTER TABLE [dbo].[PresencaAulaUnitaria]
ADD CONSTRAINT [PK_PresencaAulaUnitaria]
    PRIMARY KEY NONCLUSTERED ([AulaUnitariaSet_Id], [PresencaSet_Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [TurmaId] in table 'AlunoSet'
ALTER TABLE [dbo].[AlunoSet]
ADD CONSTRAINT [FK_AlunoTurma]
    FOREIGN KEY ([TurmaId])
    REFERENCES [dbo].[TurmaSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AlunoTurma'
CREATE INDEX [IX_FK_AlunoTurma]
ON [dbo].[AlunoSet]
    ([TurmaId]);
GO

-- Creating foreign key on [User_Id] in table 'AlunoSet'
ALTER TABLE [dbo].[AlunoSet]
ADD CONSTRAINT [FK_AlunoUser]
    FOREIGN KEY ([User_Id])
    REFERENCES [dbo].[UserSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AlunoUser'
CREATE INDEX [IX_FK_AlunoUser]
ON [dbo].[AlunoSet]
    ([User_Id]);
GO

-- Creating foreign key on [Turma_Id] in table 'AulaSet'
ALTER TABLE [dbo].[AulaSet]
ADD CONSTRAINT [FK_AulaTurma]
    FOREIGN KEY ([Turma_Id])
    REFERENCES [dbo].[TurmaSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AulaTurma'
CREATE INDEX [IX_FK_AulaTurma]
ON [dbo].[AulaSet]
    ([Turma_Id]);
GO

-- Creating foreign key on [Professor_Id] in table 'CursoSet'
ALTER TABLE [dbo].[CursoSet]
ADD CONSTRAINT [FK_CursoProfessor]
    FOREIGN KEY ([Professor_Id])
    REFERENCES [dbo].[ProfessorSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_CursoProfessor'
CREATE INDEX [IX_FK_CursoProfessor]
ON [dbo].[CursoSet]
    ([Professor_Id]);
GO

-- Creating foreign key on [Curso_Id] in table 'TurmaSet'
ALTER TABLE [dbo].[TurmaSet]
ADD CONSTRAINT [FK_TurmaCurso]
    FOREIGN KEY ([Curso_Id])
    REFERENCES [dbo].[CursoSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_TurmaCurso'
CREATE INDEX [IX_FK_TurmaCurso]
ON [dbo].[TurmaSet]
    ([Curso_Id]);
GO

-- Creating foreign key on [User_Id] in table 'ProfessorSet'
ALTER TABLE [dbo].[ProfessorSet]
ADD CONSTRAINT [FK_UserProfessor]
    FOREIGN KEY ([User_Id])
    REFERENCES [dbo].[UserSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UserProfessor'
CREATE INDEX [IX_FK_UserProfessor]
ON [dbo].[ProfessorSet]
    ([User_Id]);
GO

-- Creating foreign key on [AulaSet_Id] in table 'AulaMateria'
ALTER TABLE [dbo].[AulaMateria]
ADD CONSTRAINT [FK_AulaMateria_AulaSet]
    FOREIGN KEY ([AulaSet_Id])
    REFERENCES [dbo].[AulaSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [MateriaSet_Id] in table 'AulaMateria'
ALTER TABLE [dbo].[AulaMateria]
ADD CONSTRAINT [FK_AulaMateria_MateriaSet]
    FOREIGN KEY ([MateriaSet_Id])
    REFERENCES [dbo].[MateriaSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AulaMateria_MateriaSet'
CREATE INDEX [IX_FK_AulaMateria_MateriaSet]
ON [dbo].[AulaMateria]
    ([MateriaSet_Id]);
GO

-- Creating foreign key on [AulaSet_Id] in table 'AulaProfessor'
ALTER TABLE [dbo].[AulaProfessor]
ADD CONSTRAINT [FK_AulaProfessor_AulaSet]
    FOREIGN KEY ([AulaSet_Id])
    REFERENCES [dbo].[AulaSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [ProfessorSet_Id] in table 'AulaProfessor'
ALTER TABLE [dbo].[AulaProfessor]
ADD CONSTRAINT [FK_AulaProfessor_ProfessorSet]
    FOREIGN KEY ([ProfessorSet_Id])
    REFERENCES [dbo].[ProfessorSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AulaProfessor_ProfessorSet'
CREATE INDEX [IX_FK_AulaProfessor_ProfessorSet]
ON [dbo].[AulaProfessor]
    ([ProfessorSet_Id]);
GO

-- Creating foreign key on [AulaSet_Id] in table 'AulaUnitariaAula'
ALTER TABLE [dbo].[AulaUnitariaAula]
ADD CONSTRAINT [FK_AulaUnitariaAula_AulaSet]
    FOREIGN KEY ([AulaSet_Id])
    REFERENCES [dbo].[AulaSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [AulaUnitariaSet_Id] in table 'AulaUnitariaAula'
ALTER TABLE [dbo].[AulaUnitariaAula]
ADD CONSTRAINT [FK_AulaUnitariaAula_AulaUnitariaSet]
    FOREIGN KEY ([AulaUnitariaSet_Id])
    REFERENCES [dbo].[AulaUnitariaSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AulaUnitariaAula_AulaUnitariaSet'
CREATE INDEX [IX_FK_AulaUnitariaAula_AulaUnitariaSet]
ON [dbo].[AulaUnitariaAula]
    ([AulaUnitariaSet_Id]);
GO

-- Creating foreign key on [MateriaSet_Id] in table 'Habilitado'
ALTER TABLE [dbo].[Habilitado]
ADD CONSTRAINT [FK_Habilitado_MateriaSet]
    FOREIGN KEY ([MateriaSet_Id])
    REFERENCES [dbo].[MateriaSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [ProfessorSet_Id] in table 'Habilitado'
ALTER TABLE [dbo].[Habilitado]
ADD CONSTRAINT [FK_Habilitado_ProfessorSet]
    FOREIGN KEY ([ProfessorSet_Id])
    REFERENCES [dbo].[ProfessorSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_Habilitado_ProfessorSet'
CREATE INDEX [IX_FK_Habilitado_ProfessorSet]
ON [dbo].[Habilitado]
    ([ProfessorSet_Id]);
GO

-- Creating foreign key on [CursoSet_Id] in table 'MateriaCurso'
ALTER TABLE [dbo].[MateriaCurso]
ADD CONSTRAINT [FK_MateriaCurso_CursoSet]
    FOREIGN KEY ([CursoSet_Id])
    REFERENCES [dbo].[CursoSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [MateriaSet_Id] in table 'MateriaCurso'
ALTER TABLE [dbo].[MateriaCurso]
ADD CONSTRAINT [FK_MateriaCurso_MateriaSet]
    FOREIGN KEY ([MateriaSet_Id])
    REFERENCES [dbo].[MateriaSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_MateriaCurso_MateriaSet'
CREATE INDEX [IX_FK_MateriaCurso_MateriaSet]
ON [dbo].[MateriaCurso]
    ([MateriaSet_Id]);
GO

-- Creating foreign key on [AlunoSet_Id] in table 'PresencaAluno'
ALTER TABLE [dbo].[PresencaAluno]
ADD CONSTRAINT [FK_PresencaAluno_AlunoSet]
    FOREIGN KEY ([AlunoSet_Id])
    REFERENCES [dbo].[AlunoSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [PresencaSet_Id] in table 'PresencaAluno'
ALTER TABLE [dbo].[PresencaAluno]
ADD CONSTRAINT [FK_PresencaAluno_PresencaSet]
    FOREIGN KEY ([PresencaSet_Id])
    REFERENCES [dbo].[PresencaSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PresencaAluno_PresencaSet'
CREATE INDEX [IX_FK_PresencaAluno_PresencaSet]
ON [dbo].[PresencaAluno]
    ([PresencaSet_Id]);
GO

-- Creating foreign key on [AulaUnitariaSet_Id] in table 'PresencaAulaUnitaria'
ALTER TABLE [dbo].[PresencaAulaUnitaria]
ADD CONSTRAINT [FK_PresencaAulaUnitaria_AulaUnitariaSet]
    FOREIGN KEY ([AulaUnitariaSet_Id])
    REFERENCES [dbo].[AulaUnitariaSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [PresencaSet_Id] in table 'PresencaAulaUnitaria'
ALTER TABLE [dbo].[PresencaAulaUnitaria]
ADD CONSTRAINT [FK_PresencaAulaUnitaria_PresencaSet]
    FOREIGN KEY ([PresencaSet_Id])
    REFERENCES [dbo].[PresencaSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_PresencaAulaUnitaria_PresencaSet'
CREATE INDEX [IX_FK_PresencaAulaUnitaria_PresencaSet]
ON [dbo].[PresencaAulaUnitaria]
    ([PresencaSet_Id]);
GO

-- Creating foreign key on [UserSet_Id] in table 'EnderecoSet'
ALTER TABLE [dbo].[EnderecoSet]
ADD CONSTRAINT [FK_EnderecoSetUserSet]
    FOREIGN KEY ([UserSet_Id])
    REFERENCES [dbo].[UserSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_EnderecoSetUserSet'
CREATE INDEX [IX_FK_EnderecoSetUserSet]
ON [dbo].[EnderecoSet]
    ([UserSet_Id]);
GO

-- Creating foreign key on [AlunoSet_Id] in table 'AlunoSetAulaSet'
ALTER TABLE [dbo].[AlunoSetAulaSet]
ADD CONSTRAINT [FK_AlunoSetAulaSet_AlunoSet]
    FOREIGN KEY ([AlunoSet_Id])
    REFERENCES [dbo].[AlunoSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;
GO

-- Creating foreign key on [AulaSet_Id] in table 'AlunoSetAulaSet'
ALTER TABLE [dbo].[AlunoSetAulaSet]
ADD CONSTRAINT [FK_AlunoSetAulaSet_AulaSet]
    FOREIGN KEY ([AulaSet_Id])
    REFERENCES [dbo].[AulaSet]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AlunoSetAulaSet_AulaSet'
CREATE INDEX [IX_FK_AlunoSetAulaSet_AulaSet]
ON [dbo].[AlunoSetAulaSet]
    ([AulaSet_Id]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------